package org.wu.framework.core.exception;

import org.wu.framework.core.utils.ObjectUtils;
import org.wu.framework.core.utils.StringUtils;

/**
 * 断言工厂
 */
public class AssertFactory {


    /**
     * 数据不能为空
     *
     * @param param   参数
     * @param message 异常信息
     */
    public static void notNull(Object param, String message) {
        if (ObjectUtils.isEmpty(param)) {
            RuntimeExceptionFactory.of(message);
        }
    }

    public static void isTrue(boolean isTrue, String message) {
        if (isTrue) {
            RuntimeExceptionFactory.of(message);
        }
    }
    public static void isFalse(boolean isFalse, String message) {
        if (!isFalse) {
            RuntimeExceptionFactory.of(message);
        }
    }

    public static void hasText(String text, String message) {
        if (!StringUtils.hasText(text)) {
            throw new IllegalArgumentException(message);
        }
    }

    public static void state(boolean expression, String message) {
        if (!expression) {
            throw new IllegalStateException(message);
        }
    }
}
